package net.hn.hnms.biz.common.activiti.builder;


import net.hn.hnms.biz.common.activiti.params.ProcessQueryParam;
import net.hn.hnms.biz.common.activiti.result.ProcessTaskResult;
import net.hn.hnms.biz.common.activiti.service.ProcessApiService;

import java.util.HashMap;
import java.util.Map;

/**
 * Created on 2022/8/5.
 *
 * @author ly
 * @desc: 流程开始构造器
 */
public class ProcessStarter {

    //业务编码
    private String businessKey;
    //流程名称
    private String processName;

    //流程定义记录id
    private String processDefinitionId;

    //发起人
    private String applyUser;

    //流程版本
    private Integer version;

    //流程变量
    private Map<String, Object> variables = new HashMap<>();

    private ProcessApiService processApiService;

    private ProcessStarter() {
    }

    public ProcessStarter(ProcessApiService processApiService) {
        this.processApiService = processApiService;
    }


    public ProcessStarter businessKey(String businessKey) {
        this.businessKey = businessKey;
        return this;
    }

    public ProcessStarter processName(String processName) {
        this.processName = processName;
        return this;
    }

    public ProcessStarter applyUser(String applyUser) {
        this.applyUser = applyUser;
        return this;
    }

    public ProcessStarter version(Integer version) {
        this.version = version;
        return this;
    }

    public ProcessStarter variables(Map<String, Object> variables) {
        this.variables = variables;
        return this;
    }

    public ProcessStarter processDefinitionId(String processDefinitionId) {
        this.processDefinitionId = processDefinitionId;
        return this;
    }

    /**
     * 开始流程
     * @return ProcessTaskResult 开始流程后,可执行的流程任务信息
     */
    public ProcessTaskResult start() {
        ProcessQueryParam processQueryParam = new ProcessQueryParam();
        processQueryParam.setBusinessKey(this.businessKey);
        processQueryParam.setProcessDefinitionId(this.processDefinitionId);
        processQueryParam.setProcessName(this.processName);
        processQueryParam.setApplyUser(this.applyUser);
        processQueryParam.setVersion(this.version);
        processQueryParam.setVariables(this.variables);
        return this.processApiService.startProcess(processQueryParam);
    }

}
